import { Form } from '@douyinfe/semi-ui'
import { OptionProps } from '@douyinfe/semi-ui/lib/es/select'

interface ICSearchBooleanItem {
  required?: boolean
  field?: string
  label?: string
  optionList?: OptionProps[]
  initValue?: string | number
}

export const yesNoBoolDict: OptionProps[] = [
  { label: '是', value: 1 },
  { label: '否', value: 0 },
]

// 通用的 表单【Select】组件
export default function CSelectFormItem(props: ICSearchBooleanItem) {
  return (
    <Form.Select
      initValue={props.initValue}
      field={props.field || 'enableFlag'}
      showClear
      className="w100"
      label={props.label || '启用'}
      rules={
        props.required
          ? [{ required: true, message: `请选择${props.label}` }]
          : undefined
      }
      optionList={props?.optionList || yesNoBoolDict} // 默认为【yesNoBoolDict】
    />
  )
}
